from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-30 14:02:53.106073
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 30, Nov, 2022
Time: 14:02:58
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1006
Nobs: 856.000 HQIC: -51.4089
Log likelihood: 11243.4 FPE: 3.89325e-23
AIC: -51.6002 Det(Omega_mle): 3.50683e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298877 0.050174 5.957 0.000
L1.Burgenland 0.109451 0.034487 3.174 0.002
L1.Kärnten -0.106107 0.018371 -5.776 0.000
L1.Niederösterreich 0.210878 0.072087 2.925 0.003
L1.Oberösterreich 0.099535 0.068452 1.454 0.146
L1.Salzburg 0.251683 0.036565 6.883 0.000
L1.Steiermark 0.037054 0.047924 0.773 0.439
L1.Tirol 0.107763 0.038872 2.772 0.006
L1.Vorarlberg -0.059847 0.033497 -1.787 0.074
L1.Wien 0.055030 0.061203 0.899 0.369
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067594 0.103482 0.653 0.514
L1.Burgenland -0.030325 0.071127 -0.426 0.670
L1.Kärnten 0.047589 0.037889 1.256 0.209
L1.Niederösterreich -0.172058 0.148677 -1.157 0.247
L1.Oberösterreich 0.376327 0.141179 2.666 0.008
L1.Salzburg 0.288464 0.075413 3.825 0.000
L1.Steiermark 0.108470 0.098841 1.097 0.272
L1.Tirol 0.316615 0.080173 3.949 0.000
L1.Vorarlberg 0.023348 0.069086 0.338 0.735
L1.Wien -0.019666 0.126228 -0.156 0.876
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197768 0.025981 7.612 0.000
L1.Burgenland 0.092653 0.017858 5.188 0.000
L1.Kärnten -0.008775 0.009513 -0.922 0.356
L1.Niederösterreich 0.268386 0.037328 7.190 0.000
L1.Oberösterreich 0.114757 0.035446 3.238 0.001
L1.Salzburg 0.052649 0.018934 2.781 0.005
L1.Steiermark 0.016827 0.024816 0.678 0.498
L1.Tirol 0.098825 0.020129 4.910 0.000
L1.Vorarlberg 0.056127 0.017346 3.236 0.001
L1.Wien 0.111829 0.031692 3.529 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105096 0.026657 3.943 0.000
L1.Burgenland 0.047213 0.018322 2.577 0.010
L1.Kärnten -0.017380 0.009760 -1.781 0.075
L1.Niederösterreich 0.197038 0.038300 5.145 0.000
L1.Oberösterreich 0.280035 0.036368 7.700 0.000
L1.Salzburg 0.120275 0.019427 6.191 0.000
L1.Steiermark 0.101208 0.025462 3.975 0.000
L1.Tirol 0.123826 0.020653 5.996 0.000
L1.Vorarlberg 0.068831 0.017797 3.868 0.000
L1.Wien -0.026986 0.032517 -0.830 0.407
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130403 0.048234 2.704 0.007
L1.Burgenland -0.049199 0.033153 -1.484 0.138
L1.Kärnten -0.039522 0.017661 -2.238 0.025
L1.Niederösterreich 0.166965 0.069300 2.409 0.016
L1.Oberösterreich 0.139669 0.065805 2.122 0.034
L1.Salzburg 0.284786 0.035151 8.102 0.000
L1.Steiermark 0.033092 0.046071 0.718 0.473
L1.Tirol 0.163185 0.037369 4.367 0.000
L1.Vorarlberg 0.103949 0.032202 3.228 0.001
L1.Wien 0.068361 0.058836 1.162 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058433 0.038202 1.530 0.126
L1.Burgenland 0.042652 0.026258 1.624 0.104
L1.Kärnten 0.049821 0.013988 3.562 0.000
L1.Niederösterreich 0.227589 0.054887 4.146 0.000
L1.Oberösterreich 0.271428 0.052119 5.208 0.000
L1.Salzburg 0.058290 0.027840 2.094 0.036
L1.Steiermark -0.007066 0.036489 -0.194 0.846
L1.Tirol 0.156351 0.029597 5.283 0.000
L1.Vorarlberg 0.068419 0.025505 2.683 0.007
L1.Wien 0.074708 0.046600 1.603 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185438 0.045714 4.056 0.000
L1.Burgenland -0.004408 0.031421 -0.140 0.888
L1.Kärnten -0.060989 0.016738 -3.644 0.000
L1.Niederösterreich -0.087547 0.065679 -1.333 0.183
L1.Oberösterreich 0.192316 0.062367 3.084 0.002
L1.Salzburg 0.059829 0.033315 1.796 0.073
L1.Steiermark 0.225356 0.043664 5.161 0.000
L1.Tirol 0.495170 0.035417 13.981 0.000
L1.Vorarlberg 0.047920 0.030519 1.570 0.116
L1.Wien -0.051034 0.055762 -0.915 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158783 0.052097 3.048 0.002
L1.Burgenland -0.008823 0.035808 -0.246 0.805
L1.Kärnten 0.064778 0.019075 3.396 0.001
L1.Niederösterreich 0.202802 0.074851 2.709 0.007
L1.Oberösterreich -0.067015 0.071075 -0.943 0.346
L1.Salzburg 0.222252 0.037966 5.854 0.000
L1.Steiermark 0.113729 0.049761 2.286 0.022
L1.Tirol 0.084310 0.040362 2.089 0.037
L1.Vorarlberg 0.122220 0.034781 3.514 0.000
L1.Wien 0.108817 0.063549 1.712 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356786 0.030744 11.605 0.000
L1.Burgenland 0.009020 0.021131 0.427 0.669
L1.Kärnten -0.024787 0.011257 -2.202 0.028
L1.Niederösterreich 0.227744 0.044171 5.156 0.000
L1.Oberösterreich 0.156697 0.041943 3.736 0.000
L1.Salzburg 0.052936 0.022405 2.363 0.018
L1.Steiermark -0.017257 0.029365 -0.588 0.557
L1.Tirol 0.117666 0.023819 4.940 0.000
L1.Vorarlberg 0.072094 0.020525 3.513 0.000
L1.Wien 0.050525 0.037502 1.347 0.178
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043731 0.160962 0.191814 0.165452 0.132152 0.124641 0.070017 0.230917
Kärnten 0.043731 1.000000 0.002109 0.131848 0.045029 0.098940 0.427461 -0.050722 0.101889
Niederösterreich 0.160962 0.002109 1.000000 0.344500 0.166580 0.310693 0.128006 0.192436 0.341338
Oberösterreich 0.191814 0.131848 0.344500 1.000000 0.235248 0.339844 0.177276 0.179289 0.274384
Salzburg 0.165452 0.045029 0.166580 0.235248 1.000000 0.152984 0.145103 0.152880 0.140843
Steiermark 0.132152 0.098940 0.310693 0.339844 0.152984 1.000000 0.163596 0.148374 0.092566
Tirol 0.124641 0.427461 0.128006 0.177276 0.145103 0.163596 1.000000 0.122112 0.164078
Vorarlberg 0.070017 -0.050722 0.192436 0.179289 0.152880 0.148374 0.122112 1.000000 0.020235
Wien 0.230917 0.101889 0.341338 0.274384 0.140843 0.092566 0.164078 0.020235 1.000000